package utils;

/**
 * @ClassName ConfigUtil
 * @Date 2024/11/8 15:37 44
 * @Author Jack Chen
 * @Description api-test-REST-Assured
 * @Version 1.0
 */

import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;

//import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.builder.fluent.Configurations;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.commons.configuration2.PropertiesConfiguration;

public class ConfigUtil {
    private static final String ConfigFilePath = "src/test/resources/config/config.properties";
    private static PropertiesConfiguration config = null;

    static {
        try {
            Configurations configs = new Configurations();
            File configFile = new File(ConfigFilePath);
            config = configs.properties(configFile);
        } catch (ConfigurationException e) {
        e.printStackTrace();}
    }

    public static String getProperty(String key) {
        return config.getString(key);
    }

    public static String getProperty(String key, String defaultValue) {
        return config.getString(key, defaultValue);
    }

    public static int getIntProperty(String key) {
        return config.getInt(key);
    }

    public static int getIntProperty(String key, int defaultValue) {
        return config.getInt(key, defaultValue);
    }

    public static long getLongProperty(String key) {
        return config.getLong(key);
    }

    public static float getFloatProperty(String key) {
        return config.getFloat(key);
    }

    public static float getFloatProperty(String key, float defaultValue) {
        return config.getFloat(key, defaultValue);
    }

    public static long getLongProperty(String key, long defaultValue) {
        return config.getLong(key, defaultValue);
    }

    public static boolean getBooleanProperty(String key) {
        return config.getBoolean(key);
    }

    public static boolean getBooleanProperty(String key, boolean defaultValue) {
        return config.getBoolean(key, defaultValue);
    }

    public static Double getDoubleProperty(String key) {
        return config.getDouble(key);
    }

    public static Double getDoubleProperty(String key, double defaultValue) {
        return config.getDouble(key, defaultValue);
    }

    public static String[] getStringArrayProperty(String key) {
        return config.getStringArray(key);
    }

    public static List<Object> getList(String key) {
        return config.getList(key);
    }

    public static List<Object> getList(String key, List<Object> defaultValue) {
        return config.getList(key, defaultValue);
    }

    public static void setProperty(String key, String value) {
        config.setProperty(key, value);
    }

    public static void main(String[] args) {
        String xxx = ConfigUtil.getProperty("URL");
        System.out.println(xxx);
    }
}
